# PyJuggler is (C) Copyright 2002-2012 by Patrick Hartling
# Distributed under the GNU Lesser General Public License 2.1.  (See
# accompanying file COPYING.txt or http://www.gnu.org/copyleft/lesser.txt)

exec_prefix=	@exec_prefix@
includedir=	@includedir@/pyjutil
libdir=		@libdir@
prefix=		@prefix@
scriptdir=	$(top_srcdir)/release/scripts
topdir=		@topdir@
top_srcdir=	@top_srcdir@

srcdir=		@srcdir@

MKINSTALLDIRS=	$(scriptdir)/mkinstalldirs

CXX_WARNS_LEVEL_0=	@CXX_WARNS_LEVEL_0@
CXX_WARNS_LEVEL_1=	@CXX_WARNS_LEVEL_1@
CXX_WARNS_LEVEL_2=	@CXX_WARNS_LEVEL_2@
CXX_WARNS_LEVEL_3=	@CXX_WARNS_LEVEL_3@
CXX_WARNS_LEVEL_4=	@CXX_WARNS_LEVEL_4@
CXX_WARNS_LEVEL_5=	@CXX_WARNS_LEVEL_5@
WARNS=			2

AR=		@AR@ $(ARFLAGS)
AR_NAME_FLAG=	@AR_NAME_FLAG@
ARFLAGS=	@ARFLAGS@
CXX=		@CXX@
CXXFLAGS=	@CXXFLAGS@ @CXXFLAGS_DYNLIB@ @BOOST_PYTHON_INCLUDES@	\
		$(CXX_WARNS_LEVEL_$(WARNS)) @VPR_CXXFLAGS@
CXX_DLL=	@CXX_DLL@
DYLIB_NAME_FLAG=@DYLIB_NAME_FLAG@
RANLIB=		@RANLIB@

ifeq (@OS_TYPE@, Win32)
   ARFLAGS+=	$(LDFLAGS)
   CXXFLAGS+=	/Zm800 /GX /GR /Op /Zc:wchar_t,forScope
   CXXFLAGS_DBG=/Z7 /Od /Ob0 /MDd /DPYJUGGLER_DEBUG /DJUGGLER_DEBUG
   CXXFLAGS_OPT=/Ogity /O2 /Gs /Ob2 /MD /DPYJUGGLER_OPT /DJUGGLER_OPT /DNDEBUG
   LDFLAGS_DBG=	/DEBUG
   LDFLAGS_OPT=	/RELEASE
   LIBEXT_DBG=	_d
   LIBEXT_OPT=	
else
   CXXFLAGS_DBG=-DPYJUGGLER_DEBUG -DJUGGLER_DEBUG -g
   CXXFLAGS_OPT=-DPYJUGGLER_OPT -DJUGGLER_OPT -DNDEBUG -O2
   LDFLAGS_DBG=	-g
   LDFLAGS_OPT=	-O2
   LIBEXT_DBG=	
   LIBEXT_OPT=	
endif

CXXFLAGS+=	@PYTHON_INCLUDES@ -I$(srcdir)
OBJDIR_DBG=	obj.dbg
OBJDIR_OPT=	obj.opt

PYTHON_VERSION=		@PYTHON_VERSION@

VPR_LIBS=		@VPR_LIBS@
VPR_EXTRA_LIBS=		@VPR_EXTRA_LIBS@

ifeq ($(BUILD_TYPE), DEBUG)
   CXXFLAGS+=	$(CXXFLAGS_DBG)
   LDFLAGS+=	$(LDFLAGS_DBG)
   LIBEXT=	$(LIBEXT_DBG)
   OBJDIR=	$(OBJDIR_DBG)
else
   CXXFLAGS+=	$(CXXFLAGS_OPT)
   LDFLAGS+=	$(LDFLAGS_OPT)
   LIBEXT=	$(LIBEXT_OPT)
   OBJDIR=	$(OBJDIR_OPT)
endif

ifeq (@PLATFORM@, Darwin)
   LDFLAGS+=	-framework Python
endif

ARCEXT=		@STATICLIB_EXT@
DLLEXT=		@DYNAMICLIB_EXT@
OBJEXT=		@OBJEXT@
OBJ_NAME_FLAG=	@OBJ_NAME_FLAG@

# Source/object list.
SRCS=		InterpreterGuard.cpp
OBJS=		$(addprefix $(OBJDIR)/, $(SRCS:.cpp=.$(OBJEXT)))

LIB_PREFIX=	@LIB_PREFIX@

# Base library list.
PYJUTIL_LIB=	$(LIB_PREFIX)pyjutil$(LIBEXT)

# Static (archive) library list.
PYJUTIL_ARC=	$(PYJUTIL_LIB).$(ARCEXT)
PYJUTIL_DLL=	$(PYJUTIL_LIB).$(DLLEXT)

LIBS=		$(PYJUTIL_DLL)

vpath %.cpp $(srcdir)

# -----------------------------------------------------------------------------
# Targets
# -----------------------------------------------------------------------------

default: optim

all: optim debug

beforebuild:
	@$(MKINSTALLDIRS) $(OBJDIR)

optim:
	$(MAKE) BUILD_TYPE=OPTIMIZED beforebuild
	$(MAKE) BUILD_TYPE=OPTIMIZED libs
	$(MAKE) BUILD_TYPE=OPTIMIZED prefix="$(topdir)"			\
          exec_prefix="$(topdir)" install

debug:
	$(MAKE) BUILD_TYPE=DEBUG beforebuild
	$(MAKE) BUILD_TYPE=DEBUG libs
	$(MAKE) BUILD_TYPE=DEBUG prefix="$(topdir)"			\
          exec_prefix="$(topdir)" install

libs: $(LIBS)

install:
	$(MKINSTALLDIRS) $(includedir)
	cp -p $(srcdir)/*.h $(includedir)
	$(MKINSTALLDIRS) $(libdir)
	for lib in $(LIBS) ; do				\
            cp -p $$lib $(libdir) ;			\
          done

$(OBJDIR)/%.$(OBJEXT): %.cpp
	$(CXX) $(CXXFLAGS) $(OBJ_NAME_FLAG) -c $<

$(PYJUTIL_ARC): $(OBJS)
	$(AR) $(AR_NAME_FLAG)$@ $(OBJS)
	$(RANLIB) $@

$(PYJUTIL_DLL): $(OBJS)
	$(CXX_DLL) $(DYLIB_NAME_FLAG) $(OBJS) $(LDFLAGS) $(VPR_LIBS)	\
          $(VPR_EXTRA_LIBS)

#%.$(ARCEXT): %.$(OBJEXT)
#	$(CXX) -shared -o $@ $< $(BOOST_PYTHON_LDFLAGS)			\
#          $(PYTHON_LDFLAGS) $(LIBS) $(EXTRA_LIBS)

#%.$(DLLEXT): %.$(OBJEXT)
#	$(CXX) -shared -o $@ $< $(BOOST_PYTHON_LDFLAGS)			\
#          $(PYTHON_LDFLAGS) $(LIBS) $(EXTRA_LIBS)

cleandepend:
	rm -f $(DEPEND_FILES)

clean:
	rm -rf $(OBJDIR_DBG) $(OBJDIR_OPT)
	rm -f $(DEPEND_FILES)

clobber:
	$(MAKE) clean
	rm -f $(LIBS)

# -----------------------------------------------------------------------------
# Dependency generation.
# -----------------------------------------------------------------------------
BASIC_OBJECTS=	$(SRCS:.cpp=.$(OBJEXT))
MKDEP_C=	$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -M
MKDEP_CXX=	$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) -M

include $(top_srcdir)/dpp/mk/dpp.dep.mk
-include $(DEPEND_FILES)
